package com.wmh.baseservice.robot.convert;

import cn.hutool.core.collection.CollUtil;
import com.wmh.baseservice.admin.entity.AdInfo;
import com.wmh.baseservice.robot.entity.RobotTaskAdPushUnit;
import com.wmh.baseservice.robot.pojo.dto.robottaskadpushunit.RobotTaskAdPushUnitPushReqVO;
import com.wmh.baseservice.robot.pojo.vo.robottaskadpushunit.RobotTaskAdPushUnitCreateReqVO;
import com.wmh.baseservice.robot.pojo.vo.robottaskadpushunit.RobotTaskAdPushUnitUpdateReqVO;
import com.wmh.baseservice.common.utils.SnowFlakeIdUtil;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

import java.util.List;
import java.util.Map;

/**
 * @author 谢骏
 * @date 2023/9/8 10:42
 **/
@Mapper
public interface RobotTaskAdPushUnitConvert {

    RobotTaskAdPushUnitConvert INSTANCE = Mappers.getMapper(RobotTaskAdPushUnitConvert.class);

    RobotTaskAdPushUnit convert(RobotTaskAdPushUnitCreateReqVO reqVO, Long adId);

    RobotTaskAdPushUnit convert(RobotTaskAdPushUnitUpdateReqVO reqVO, Long adId);

    @Mapping(source = "unit.id", target = "pushTaskId")
    RobotTaskAdPushUnitPushReqVO.Item subConvert(RobotTaskAdPushUnit unit,String robotTaskName, Long statementId);

    default RobotTaskAdPushUnitPushReqVO convert1(List<RobotTaskAdPushUnit> unitList, Map<Long,String> nameMap, AdInfo adInfo, Boolean isTest, Integer pushTaskType) {
        RobotTaskAdPushUnitPushReqVO r = new RobotTaskAdPushUnitPushReqVO();
        r.setAdId(adInfo.getId()).setAdEmail(adInfo.getEmail()).setIsTest(isTest).setPushTaskType(pushTaskType);
        r.setTaskList(CollUtil.map(unitList, i -> subConvert(i,nameMap.get(i.getRobotTaskId()), SnowFlakeIdUtil.generate()), true));
        return r;
    }
}
